package com.briup.jz.service.impl;

import com.briup.jz.bean.Comment;
import com.briup.jz.bean.CommentExample;
import com.briup.jz.dao.CertificationApplyMapper;
import com.briup.jz.dao.CommentMapper;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {

    @Resource
    private CommentMapper commentMapper;
    @Override
    public void saveOrUpdat(Comment comment) throws CustomerException {

        if (comment.getId()!=null){
            //更新操作
            commentMapper.updateByPrimaryKey(comment);
        }else {
            commentMapper.insert(comment);
        }
    }

    @Override
    public List<Comment> query(String commnet) {

//        创建参数模板
        CommentExample example=new CommentExample();
       if (commnet!=null){
           //进行条件查询模糊查询
           example.createCriteria().andCommentLike("%"+commnet+"%");

       }
       //参数为空时，进行全部查询
        return commentMapper.selectByExample(example);
    }

    @Override
    public void deleteById(Long id) throws CustomerException {

        commentMapper.deleteByPrimaryKey(id);
    }
}
